home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: undoAppendLargeSlots.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:56:04 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
-
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "thread.h"
- #include "latch.h"
- #include "semaphore.h"
- #include "link.h"
- #include "lsn.h"
- #include "bf.h"
- #include "pool.h"
- #include "log.h"
- #include "volume.h"
- #include "trans.h"
- #include "logrecs.h"
- #include "logaction.h"
- #include "openlog.h"
- #include "undo.h"
- #include "undo_extfuncs.h"
- #include "bf_extfuncs.h"
- #include "log_extfuncs.h"
- #include "log_intfuncs.h"
- #include "util_funcs.h"
- #include "thread_globals.h"
- #include "bf_globals.h"
- #include "trans_globals.h"
- #include "sm_macro.h"
- #ifdef INIT_LRC_IS_LSN
- # include "log_globals.h"
- #endif
-
- void
- undoAppendLargeSlots(
-
- LOGRECORDHDR *recordHeader
- )
- {
-
- GROUPLINK *groupLink;
- LGNODE *lgNode;
- SLOTTEDPAGE *slottedPage;
- PAGETYPE pageType;
- PAGE2SIZE page2size;
- PAGESLOT *slotPtr;
- SMALLOBJ *objPtr;
- LRC *pageLRC;
- PID *pid;
- LGWRITEINFO *lgWriteInfo;
- LOGRECORDINFO recordInfo;
- #ifdef INIT_LRC_IS_LSN
- LRC tempLRC;
- LRC *lrc = &tempLRC;
- #else
- LRC *lrc;
- #endif /* INIT_LRC_IS_LSN; */
- LSN lsn;
- FORCEMARK forceMark;
- BOOL actionDone; /* Indicates whether the action
- was ever performed on the page */
- INIT_MISSING_UPDATE_INFO( Active->transRec );
-
- TRPRINT(TR_IO, TR_LEVEL_1, ("lsn:%d", recordHeader->recordLSN));
-
- /*
- * get a pointer to the page for the record
- */
- pid = &(recordHeader->actionPid);
- TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("pid:%d", pid->page));
-
- /*
- * get pointer to oid, header info
- */
- lgWriteInfo = (LGWRITEINFO*) GET_LOG_IMAGE(recordHeader, 0);
-
- /*
- * read in the page
- */
- if (lgWriteInfo->rootSlot != NIL) {
- pageType = PAGE_SLOTTED;
- page2size = SLOTTED_PAGE2SIZE;
- } else {
- pageType = PAGE_LARGENODE;
- page2size = LG_PAGE2SIZE;
- }
- if ((groupLink = bf_ReadPage(UserBufGroup, pid, page2size, BF_SEM)) == NULL) {
-
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
- groupLink->pageHash->pageType = pageType;
-
- /*
- * get a pointer to the large node page
- */
- if (lgWriteInfo->rootSlot == NIL) {
- lgNode = (LGNODE *) groupLink->bufFrame;
- pageLRC = &(lgNode->header.lrc);
- CHECK_LARGENODE_MAGIC(lgNode);
- } else {
- /*
- * Root node on slotted page
- */
- slottedPage = (SLOTTEDPAGE *) groupLink->bufFrame;
- pageLRC = &(slottedPage->header.lrc);
- SM_ASSERT(LEVEL_3, !CHECK_SLOTTED_MAGIC(slottedPage));
- }
-
- /*
- * See if the action was actually done
- */
- actionDone = compareLRC(&(recordHeader->actionLRC), pageLRC) <= 0;
-
- /*
- * it is possible that the action
- * never made it to the page on the server, so missing update
- * information may need to be recorded
- *
- * Process any missing updates, and return a pointer to
- * the lrc to increment. This will either be the lrc on the
- * slotted page, or the lrc in the missingUpdatePageTable
- */
- RECORD_MISSING_UPDATE(actionDone, &lrc ,missingUpdateInfo, pid,
- pageLRC, groupLink->pageHash, recordHeader, pageType);
-
- /*
- * increment the lrc on the page
- */
- GENERATE_LRC(lrc);
-
- /*
- * Log the undo of the append
- */
- if (recordHeader->action == LOG_ACTION_APPEND_LARGE_SLOTS) {
- recordInfo.action = LOG_ACTION_REMOVE_LARGE_SLOTS;
- } else {
- SM_ASSERT(LEVEL_3, recordHeader->action == LOG_ACTION_INSERT_LARGE_SLOTS);
- recordInfo.action = LOG_ACTION_DELETE_LARGE_SLOTS;
- }
- recordInfo.type = LOG_REC_TYPE_COMPENSATION;
- recordInfo.imageCount = 1;
- recordInfo.actionPid = pid;
- recordInfo.actionLRC = lrc;
- recordInfo.imageSize[0] = sizeof(LGWRITEINFO);
- recordInfo.imageData[0] = (VOID *) lgWriteInfo;
- recordInfo.nextUndoLSN = recordHeader->previousLSN;
- recordInfo.flags = NOFLAGS;
-
- /*
- * write the record to the log
- */
- if ((forceMark = writeLogRecord((TRANSREC *) Active->transRec, &recordInfo,
- &lsn, NOFLAGS)) < 0) {
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
-
- /*
- * mark the page dependency
- */
- #ifndef INIT_LRC_IS_LSN
- DEPEND_LOG(groupLink->pageHash, forceMark, &lsn, lrc);
- #endif
-
- /*
- * perform the undo, if the action was performed
- */
- if (actionDone) {
-
- #ifdef INIT_LRC_IS_LSN
- DEPEND_LOG(groupLink->pageHash, forceMark, &lsn, lrc);
- #endif
-
- /*
- * get a pointer to the large node page
- */
- if (lgWriteInfo->rootSlot != NIL) {
- /*
- * Root node on slotted page
- */
- SM_ASSERT(LEVEL_3, lgWriteInfo->rootSlot < slottedPage->header.slotCount);
- slotPtr = GETSLOTPTR(slottedPage, lgWriteInfo->rootSlot);
- objPtr = GETOBJECTPTR(slottedPage, slotPtr);
- lgNode = (LGNODE*) objPtr->data;
- CHECK_SLOTROOT_MAGIC(lgNode);
- }
-
- if (recordHeader->action == LOG_ACTION_INSERT_LARGE_SLOTS) {
- /*
- * Shift slots down to delete
- */
- bcopy( ((char*)lgNode->slot)+lgWriteInfo->start+lgWriteInfo->size,
- ((char*)lgNode->slot)+lgWriteInfo->start,
- (int) (lgNode->header.numSlots*sizeof(LGSLOT)) - lgWriteInfo->start - lgWriteInfo->size);
-
- }
-
- /*
- * Restore the old data
- */
- lgNode->header.numSlots -= lgWriteInfo->size / sizeof(LGSLOT);
- }
-
- /*
- * signal the semaphore and unfix the page, dirty the page if
- * the action was done
- */
- signalSemaphore( &(groupLink->pageHash->semaphore) );
- bf_UnfixPage(groupLink, BF_DEFAULT, actionDone);
-
- /*
- * return success
- */
- return;
- }
-